//
//  stuCustomCell.m
//  ChatDemo-UI2.0
//
//  Created by zz on 16/5/19.
//  Copyright © 2016年 zz. All rights reserved.
//

#import "stuCustomCell.h"

@implementation stuCustomCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        _headImage = [[XZHeaderImageView alloc] initWithFrame:CGRectMake(12, 13, 45, 45)];
        [self.contentView addSubview:_headImage];
        
        _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_headImage.frame)+20, 27, 120, 16)];
        _nameLabel.textColor = RGBACOLOR(59, 59, 59, 1);
        _nameLabel.font = [UIFont boldSystemFontOfSize:16];
        [self.contentView addSubview:_nameLabel];
        
        _classLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_headImage.frame)+20, CGRectGetMaxY(_nameLabel.frame)+7, 120, 14)];
        _classLabel.textColor = RGBACOLOR(150, 150, 150, 1);
        _classLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:_classLabel];
        
        _towImageView = [[UIImageView alloc] initWithFrame:CGRectMake(SCREENWIDTH-56, 22, 46, 27)];
        _towImageView.image = [UIImage imageNamed:@"erweunahuabtiy_grxx_3_nor"];
        [self.contentView addSubview:_towImageView];
    }
    
    return self;
}

-(void)updateCellWithDic:(NSDictionary *)dic{
    
    NSString *logo = [dic objectForKey:@"logo"];
    int type = [[dic objectForKey:@"logotype"] intValue];
    
    NSString *username = [dic objectForKey:@"studentname"];
    _nameLabel.text = username;
    if (username.length == 0) {
        _nameLabel.text = [dic objectForKey:@"username"];
    }
    
    _classLabel.text = [dic objectForKey:@"classname"];
    
    if (logo.length == 0) { //没有头像的情况
        logo = @"http://file.our100.net/logo/logo_04.png";
        
    }else{
        
        if (![logo hasPrefix:@"http"]) {
            logo = [REQUESTIMAGEURL stringByAppendingString:logo];
        }
    }
    
    if (username.length > 2) {
        username = [username substringFromIndex:username.length - 2];
    }
    
    [_headImage updateViewWithLogoStr:logo];
    _headImage.namelabel.text = username;
    _headImage.namelabel.font = [UIFont systemFontOfSize:14];
    _headImage.flag = type == 1?YES:NO;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
